<template>
  <div class="login-conter">
    <div class="conter">
      <div class="conter-left">
        <div class="conter-leftimg">
          <img style="width:100%" src="@/assets/admin/logo.png" alt />
        </div>
        <div>欢迎！</div>
        <div>智学商城-后台管理系统</div>
      </div>
      <div class="conter-right">
        <div class="right-title">登录</div>
        <div>
          <el-input
            class="inputs"
            v-model="FormData.username "
            placeholder="请输入账号"
            :prefix-icon="User"
          />
        </div>
        <div>
          <el-input
            class="inputs"
            v-model="FormData.password"
              type="password"
            placeholder="请输入密码"
            :prefix-icon="Lock"
             show-password
          />
        </div>
        <el-button class="buttons" type="primary" @click="submit">登录</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { User, Lock } from "@element-plus/icons-vue";
import http from "@/util/http";
import { ElMessage } from "element-plus";
import Cookies from "js-cookie";
export default {
  data() {
    return {
      Lock,
      User,
      FormData: {
        _gp: "admin",
        _mt: "login",
        username: "zm",
        password: "123456",
      },
      mydata:{},
    };
  },
  created(){

  },
  methods: {
    submit() {
      console.log(111);
      if (this.FormData.username.length == 0) {
        ElMessage({
          showClose: true,
          message: "请输入账号",
          type: "warning",
        });
        //  ElMessage.warning("请输入账号")
        return;
      }
      if (this.FormData.password.length == 0) {
        ElMessage({
          showClose: true,
          message: "请输入密码",
          type: "warning",
        });
        //  ElMessage.warning("请输入密码")
        return;
      }
      if (this.FormData.username != "" && this.FormData.username != "") {
        http
          .post(this.FormData)
          .then((res) => {

            if (200 == res.data.errno ) {
              // let time = new Date().getHours();//9个小时
              Cookies.set("token", res.data.data, {  expires: 1 / 24 / 2 });// 将token存储在Cookies里,设置过期时间为半个小时
               if (this.$route.query.ind) {
                //如果路由前置守卫有标记
                this.$router.push({ path: this.$route.query.ind }); //那么路由就跳入标记的路由页面
              } else {
                this.$router.push({ path: "/" }); //否则就跳到首页
              }
            } else {
              ElMessage({
                showClose: true,
                message: "res.data.errmsg",
                type: "warning",
              });
            }
          })
          .catch((err) => {
            console.log(err, "请求失败");
          });
      } else {
      }
    },
  },
};
</script>
<style lang="less" scoped>
.login-conter {
  width: 100%;
  // height: ;
  height: 100vh;
  padding-top: 100px;
  background-image: url("../assets/admin/login-back.png");
  background-size: 100%;
  .conter {
    width: 50%;
    height: 50%;
    margin: auto;
    display: flex;
    white-space: nowrap;
    .conter-left {
      width: 35%;
      height: 80%;
      color: #fff;
      margin: 0;
      background-color: rgb(55, 85, 254);
      text-align: center;
      padding-top: 72px;
      .conter-leftimg {
        width: 100px;
        border-radius: 50%;
        margin: auto;
        overflow: hidden;
        margin-bottom: 20px;
        box-shadow: rgba(255, 255, 255, 0.3) 3px 0px 8px 8px;
      }
    }
    .conter-right {
      width: 65%;
      height: 100%;

      background-color: #fff;
      text-align: center;
      .right-title {
        margin-top: 60px;
      }
      .inputs {
        width: 260px;
        margin-top: 20px;
      }
      .buttons {
        width: 120px;
        margin-top: 20px;
      }
    }
  }
}
</style>